package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/description/?envType=study-plan-v2&envId=top-100-liked
 * AC 通过
 *
 * @author yulongTian
 * @create 2024-07-10 16:07
 */
public class Test65 {
    public static void main(String[] args) {

    }

    public int findMin(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int mid;
        int len = nums.length;
        if (nums[0] <= nums[len - 1]) {
            return nums[0];
        } else {
            // 先找到转折起始点
            while (left <= right) {
                mid = left + (right - left) / 2;
                if (nums[mid] > nums[len - 1]) {
                    left = mid + 1;
                } else if (nums[mid] < nums[0]) {
                    right = mid - 1;
                }
            }
            return nums[left];
        }

    }

}
